<!DOCTYPE html>
<html>
<head>
  <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
  <title>The source code</title>
  <link href="../resources/prettify/prettify.css" type="text/css" rel="stylesheet" />
  <script type="text/javascript" src="../resources/prettify/prettify.js"></script>
  <style type="text/css">
    .highlight { display: block; background-color: #ddd; }
  </style>
  <script type="text/javascript">
    function highlight() {
      document.getElementById(location.hash.replace(/#/, "")).className = "highlight";
    }
  </script>
</head>
<body onload="prettyPrint(); highlight();">
  <pre class="prettyprint lang-js"><span id='Ext-Template'>/**
</span> * @class Ext.Template
 */
Ext.apply(Ext.Template.prototype, {
<span id='Ext-Template-cfg-disableFormats'>    /**
</span>     * @cfg {Boolean} disableFormats Specify &lt;tt&gt;true&lt;/tt&gt; to disable format
     * functions in the template. If the template does not contain
     * {@link Ext.util.Format format functions}, setting &lt;code&gt;disableFormats&lt;/code&gt;
     * to true will reduce &lt;code&gt;{@link #apply}&lt;/code&gt; time. Defaults to &lt;tt&gt;false&lt;/tt&gt;.
     * &lt;pre&gt;&lt;code&gt;
var t = new Ext.Template(
    '&amp;lt;div name=&quot;{id}&quot;&amp;gt;',
        '&amp;lt;span class=&quot;{cls}&quot;&amp;gt;{name} {value}&amp;lt;/span&amp;gt;',
    '&amp;lt;/div&amp;gt;',
    {
        compiled: true,      // {@link #compile} immediately
        disableFormats: true // reduce &lt;code&gt;{@link #apply}&lt;/code&gt; time since no formatting
    }
);
     * &lt;/code&gt;&lt;/pre&gt;
     * For a list of available format functions, see {@link Ext.util.Format}.
     */
    disableFormats : false,
<span id='Ext-Template-property-disableFormats'>    /**
</span>     * See &lt;code&gt;{@link #disableFormats}&lt;/code&gt;.
     * @type Boolean
     * @property disableFormats
     */

<span id='Ext-Template-property-re'>    /**
</span>     * The regular expression used to match template variables
     * @type RegExp
     * @property
     * @hide repeat doc
     */
    re : /\{([\w\-]+)(?:\:([\w\.]*)(?:\((.*?)?\))?)?\}/g,
    argsRe : /^\s*['&quot;](.*)[&quot;']\s*$/,
    compileARe : /\\/g,
    compileBRe : /(\r\n|\n)/g,
    compileCRe : /'/g,

<span id='Ext-Template-method-applyTemplate'>    /**
</span>     * Returns an HTML fragment of this template with the specified values applied.
     * @param {Object/Array} values The template values. Can be an array if your params are numeric (i.e. {0}) or an object (i.e. {foo: 'bar'})
     * @return {String} The HTML fragment
     * @hide repeat doc
     */
    applyTemplate : function(values){
        var me = this,
            useF = me.disableFormats !== true,
            fm = Ext.util.Format,
            tpl = me;

        if(me.compiled){
            return me.compiled(values);
        }
        function fn(m, name, format, args){
            if (format &amp;&amp; useF) {
                if (format.substr(0, 5) == &quot;this.&quot;) {
                    return tpl.call(format.substr(5), values[name], values);
                } else {
                    if (args) {
                        // quoted values are required for strings in compiled templates,
                        // but for non compiled we need to strip them
                        // quoted reversed for jsmin
                        var re = me.argsRe;
                        args = args.split(',');
                        for(var i = 0, len = args.length; i &lt; len; i++){
                            args[i] = args[i].replace(re, &quot;$1&quot;);
                        }
                        args = [values[name]].concat(args);
                    } else {
                        args = [values[name]];
                    }
                    return fm[format].apply(fm, args);
                }
            } else {
                return values[name] !== undefined ? values[name] : &quot;&quot;;
            }
        }
        return me.html.replace(me.re, fn);
    },

<span id='Ext-Template-method-compile'>    /**
</span>     * Compiles the template into an internal function, eliminating the RegEx overhead.
     * @return {Ext.Template} this
     * @hide repeat doc
     */
    compile : function(){
        var me = this,
            fm = Ext.util.Format,
            useF = me.disableFormats !== true,
            sep = Ext.isGecko ? &quot;+&quot; : &quot;,&quot;,
            body;

        function fn(m, name, format, args){
            if(format &amp;&amp; useF){
                args = args ? ',' + args : &quot;&quot;;
                if(format.substr(0, 5) != &quot;this.&quot;){
                    format = &quot;fm.&quot; + format + '(';
                }else{
                    format = 'this.call(&quot;'+ format.substr(5) + '&quot;, ';
                    args = &quot;, values&quot;;
                }
            }else{
                args= ''; format = &quot;(values['&quot; + name + &quot;'] == undefined ? '' : &quot;;
            }
            return &quot;'&quot;+ sep + format + &quot;values['&quot; + name + &quot;']&quot; + args + &quot;)&quot;+sep+&quot;'&quot;;
        }

        // branched to use + in gecko and [].join() in others
        if(Ext.isGecko){
            body = &quot;this.compiled = function(values){ return '&quot; +
                   me.html.replace(me.compileARe, '\\\\').replace(me.compileBRe, '\\n').replace(me.compileCRe, &quot;\\'&quot;).replace(me.re, fn) +
                    &quot;';};&quot;;
        }else{
            body = [&quot;this.compiled = function(values){ return ['&quot;];
            body.push(me.html.replace(me.compileARe, '\\\\').replace(me.compileBRe, '\\n').replace(me.compileCRe, &quot;\\'&quot;).replace(me.re, fn));
            body.push(&quot;'].join('');};&quot;);
            body = body.join('');
        }
        eval(body);
        return me;
    },

    // private function used to call members
    call : function(fnName, value, allValues){
        return this[fnName](value, allValues);
    }
});
Ext.Template.prototype.apply = Ext.Template.prototype.applyTemplate;
</pre>
</body>
</html>
